
from multiprocessing import cpu_count
# from multiprocessing.dummy import Queue,Manager,Pool,Process
from multiprocessing.dummy import Pool, Process, Manager
# from multiprocessing import Manager
import time
import threading
import os
import asyncio
'''
10w 3.3s
10w 0.5

'''
async def work(arg):
    while 1:
        v = arg.get()
        if v == 'kill':
            arg.put('kill')
            break
        await asyncio.sleep(0.1)
        v += v
        print('%s : %s' % (os.getpid(), v))



def say(work_queue):
    loop = asyncio.new_event_loop()
    asyncio.set_event_loop(loop)

    # loop = asyncio.get_event_loop()
    tasks = [asyncio.ensure_future(work(work_queue)) for i in range(5)]
    loop.run_until_complete(asyncio.wait(tasks))
    loop.close()

pool = Pool(2)
manager = Manager()
q = manager.Queue()




for i in range(2):
    pool.map_async(say, (q,))



# for job in jobs:
#     job.get()
print(4)
a = time.time()
for i in range(50):
    q.put(i)
q.put('kill')



pool.close()
pool.join()

# for p in process:
#   p.join()

print(time.time() - a)


import asyncio
from multiprocessing import Process 

@asyncio.coroutine
def coro():
    print("hi")

def worker():
    loop = asyncio.get_event_loop()
    loop.run_until_complete(coro())

if __name__ == "__main__":
    p = Process(target=worker)
    p1 = Process(target=worker)
    p.start()
    p.join()
    p1.start()
    p1.join()